#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>


//  int mkfifo(const char *pathname, mode_t mode);

int main(){

	char *msg="message from FIFO";
	int cnt = 0;

	if((mkfifo("./file",0600) == -1) && errno != EEXIST){
	
		printf("mkfifo failed!\n");
		perror("why");
	}

	int fd = open("./file",O_WRONLY);
	if(fd < 0){
		
		printf("open error!\n");
	}
	else if(fd > 0){

		while(1){
	
			sleep(2);
			int n_write = write(fd,msg,strlen(msg));
			printf("write %d byte to FIFO\n",n_write);
			cnt++;
			if(cnt == 5)break;
		}
	}
	close(fd);
	return 0;
}
